<template>
  <div class="goods-info">
    <div class="my-panel">
      <Swiper :list="lunbolist"></Swiper>
    </div>
    <van-panel
      class="my-panel"
      :title="goodsinfo.title"
    >
      <div class="content">
        <p class="price">
          <!-- 过滤器写法 -->
          <span class="new">现价:{{goodsinfo.sell_price | pricefmt}}</span>
          <!-- mixins写法 -->
          <span class="new">现价:{{filterPrice(goodsinfo.sell_price)}}</span>
          <span class="old">原价:{{goodsinfo.market_price | pricefmt}}</span>
        </p>
        <p class="number">
          购买数量:
          <van-stepper v-model="value" />
        </p>
      </div>
    </van-panel>
    <van-panel
      class="my-panel"
      title="商品信息"
    >
      <div class="content">
        <p>商品货号:{{goodsinfo.goods_no}}</p>
        <p>库存情况:{{goodsinfo.stock_quantity}}件</p>
        <p>上架时间:{{goodsinfo.add_time | datefmt}}</p>
      </div>
    </van-panel>

    <van-goods-action>
      <van-goods-action-icon
        icon="chat-o"
        text="客服"
        color="#ee0a24"
      />
      <van-goods-action-icon
        icon="cart-o"
        text="购物车"
        :info="$store.getters['cart/getAllCount']"
        to="/cart"
      />
      <van-goods-action-icon
        icon="star"
        text="已收藏"
        color="#ff5000"
      />
      <van-goods-action-button
        type="warning"
        text="加入购物车"
        @click="addCart"
      />
      <van-goods-action-button
        type="danger"
        text="立即购买"
      />
    </van-goods-action>
  </div>
</template>
<script>
import Swiper from '@/components/Swiper'
export default {
  components: {
    Swiper
  },
  props: ['id'],
  data() {
    return {
      lunbolist: [],
      value: 1,
      goodsinfo: {}
    }
  },
  created() {
    this.getLunbo()
    this.getGoodsInfo()
    // console.log(this.$store.getters['cart/getAllCount'])
  },
  methods: {
    async getLunbo() {
      const res = await this.$http.getThumImages(this.id)
      this.lunbolist = res.data.message
    },
    async getGoodsInfo() {
      const res = await this.$http.getGoodsInfo(this.id)
      this.goodsinfo = res.data.message
    },
    addCart() {
      const goodsinfo = {
        id: this.id,
        icon: this.lunbolist[0].src,
        price: this.goodsinfo.sell_price,
        count: this.value,
        title: this.goodsinfo.title,
        timer: null,
        checked: true
      }
      this.$store.commit('cart/ADD_COUNT', goodsinfo)
    }
  }
}
</script>
<style lang="scss">
.goods-info {
  padding: 10px;
  .my-swipe {
    text-align: center;
    padding: 10px;
    box-sizing: border-box;
    img {
      width: 50%;
      height: 100%;
    }
  }
  .my-panel {
    border: 1px solid #eee;
    margin-bottom: 10px;
    .van-cell__title {
      font-size: 14px;
      font-weight: 600;
    }
    .content {
      margin-left: 15px;
      font-size: 12px;
      .price {
        .new {
          color: red;
          margin-right: 20px;
        }
        .old {
          text-decoration: line-through;
        }
      }
      .number {
        display: flex;
        align-items: center;
      }
    }
  }
}
</style>